# nickcutter.pl
# vi: et sw=2
#
# Long nick cutter
# Copyright (C) 2009  Harry Karvonen
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
# Author: Harry Karvonen <harry.karvonen@gmail.com>
#

#
# Version: 0.1
#

use strict;

my $cmd = "nick_max_lenght";
my $version = "0.1";
my $nick_max_length = 15;

Xchat::register("Nick cutter", $version, "Cut long nicknames");

Xchat::hook_command("nick_max_length", "callback2");
Xchat::hook_print("Channel Message", "callback");

sub callback {
  my $nick = Xchat::strip_code($_[0][0]);

  if (length $nick > $nick_max_length) {
    my $cutted_nick = substr ($nick, 0, ($nick_max_length - 3));
#    Xchat::print($nick . " parsitaan " . $cutted_nick);
    Xchat::emit_print("Channel Message",
		($cutted_nick."...", $_[0][1], $_[0][2], $_[0][3]));
    return Xchat::EAT_XCHAT;
  }

  return Xchat::EAT_NONE;
}

sub callback2
{
  $nick_max_length = $_[0][1];

  Xchat::print("Nick max length is now $nick_max_length");

  return Xchat::EAT_XCHAT;
}

Xchat::print("Nick cutter v$version - max nick length $nick_max_length");
